package com.juicygames.framework.property.space;

import android.graphics.Rect;

import com.juicygames.framework.action.UpdateAction;
import com.juicygames.framework.handler.UpdateHandler;
import com.juicygames.framework.property.RectProperty;
import com.juicygames.framework.type.Point;

public class BoundingBox extends RectProperty {
	
	public BoundingBox(Rect rect) {
		super(rect);
	}
	
	public void load() {
		Position position = parent.getPart(Position.class);
		addPart(new TouchBoundingBoxUpdateHandler(position));
	}
	
	public void move(Point point) {
		rect.offsetTo(point.x - rect.width() / 2, point.y - rect.height() / 2);
	}
	
	class TouchBoundingBoxUpdateHandler extends UpdateHandler {
		
		Position position;
		
		public TouchBoundingBoxUpdateHandler(Position position) {
			super();
			this.position = position;
		}
		
		public void handle(UpdateAction update) {
			((BoundingBox)parent).move(position.get());
		}
	}

}
